<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>/net/nas/exports/srv/www/webapps/Projects/Java/CS222/Seminar_1/AssignmentThree/src/WhileTimes.java.html</title>
<meta name="Generator" content="Vim/7.1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000"><font face="monospace">
<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;WhileTimes.java</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;Code the WhileTimes.java program from page A-31.</font><font color="#0000ff">&nbsp;Compile and run the program.</font><br>
<font color="#0000ff">&nbsp;* Convert the program from a while loop to a for loop. That is, rewrite the </font><br>
<font color="#0000ff">&nbsp;* program using a for loop instead of the while loop. Compile and run the </font><br>
<font color="#0000ff">&nbsp;* program and then post your completed for-loop program to the Forum labeled </font><br>
<font color="#0000ff">&nbsp;* Seminar One Answer Forum. (50 points)</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* </font><font color="#6a5acd">@author</font><font color="#0000ff">: John Thomason</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;Date: Nov 8, 2008 / 7:28:10 AM</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp; Class: CS222 Java II</font><br>
<font color="#0000ff">&nbsp;*/</font><br>
<br>
<br>
<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;WhileTimes Class</font><br>
<font color="#6a5acd">&nbsp;</font><font color="#0000ff">*/</font><br>
<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>class</b></font>&nbsp;WhileTimes {<br>
<br>
&nbsp;&nbsp;<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;Application Entry Point</font><br>
<font color="#0000ff">&nbsp;&nbsp; </font><font color="#0000ff">* </font><font color="#6a5acd">@param</font><font color="#008b8b">&nbsp;args</font><font color="#0000ff">&nbsp;The command line arguments</font><br>
<font color="#0000ff">&nbsp;&nbsp; */</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>static</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;main(String[]&nbsp;args)&nbsp;{<br>
&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;ObjectFour four = <font color="#a52a2a"><b>new</b></font>&nbsp;ObjectFour();<br>
&nbsp;&nbsp;&nbsp;&nbsp;four.go();<br>
&nbsp;&nbsp; <br>
&nbsp;&nbsp;}<font color="#0000ff">//end main()</font><br>
<br>
}<font color="#0000ff">//end WhileTimes class</font><br>
<br>
<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;ObjectFour Class</font><br>
<font color="#6a5acd">&nbsp;</font><font color="#0000ff">*/</font><br>
<font color="#2e8b57"><b>class</b></font>&nbsp;ObjectFour {<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;go(){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;Original nested while loops</font><br>
<font color="#6a5acd">&nbsp;&nbsp;&nbsp;&nbsp;int x,y;</font><br>
<font color="#6a5acd">&nbsp;&nbsp;&nbsp;&nbsp;</font><br>
<font color="#6a5acd">&nbsp;&nbsp;&nbsp;&nbsp;y = 1;</font><br>
<font color="#6a5acd">&nbsp;&nbsp;&nbsp;&nbsp;while( y </font><font color="#008b8b">&lt;=</font><font color="#ff00ff">&nbsp;10</font><font color="#008b8b">&nbsp;){</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x =</font><font color="#ff00ff">&nbsp;1;</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while( x </font><span style="background-color: #ff0000"><font color="#ffffff">&lt;</font></span><font color="#008b8b">=</font><font color="#ff00ff">&nbsp;10</font><font color="#008b8b">&nbsp;){</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print( </font><font color="#ff00ff">&quot; &quot;</font><font color="#008b8b">&nbsp;+ (x * y));</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x =</font><font color="#ff00ff">&nbsp;x</font><font color="#008b8b">&nbsp;+ 1;</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}//inner while()</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y =</font><font color="#ff00ff">&nbsp;y</font><font color="#008b8b">&nbsp;+ 1;</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp;}//outer while()</font><br>
<font color="#008b8b">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000ff">*/</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;Recoded nested for loops</font><br>
<font color="#6a5acd">&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000ff">*/</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>for</b></font>(&nbsp;<font color="#2e8b57"><b>int</b></font>&nbsp;y = <font color="#ff00ff">1</font>; y &lt;= <font color="#ff00ff">10</font>; y++ ){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>for</b></font>(&nbsp;<font color="#2e8b57"><b>int</b></font>&nbsp;x = <font color="#ff00ff">1</font>; x &lt;= <font color="#ff00ff">10</font>; x++ ){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.printf(<font color="#ff00ff">&quot;%4d&quot;</font>, (x * y));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<font color="#0000ff">//inner for()</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<font color="#0000ff">//outer for()</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;}<font color="#0000ff">//end go()</font><br>
&nbsp;&nbsp;<br>
}<font color="#0000ff">//end ObjectFour</font><br>
</font></body>
</html>
